home *** CD-ROM | disk | FTP | other *** search
-
- package sub_arctic.lib;
-
- import sub_arctic.output.loaded_image;
- import sub_arctic.output.drawable;
- import sub_arctic.input.pressable;
- import sub_arctic.input.grow_draggable;
- import sub_arctic.input.event;
- import sub_arctic.input.pick_collector;
- import sub_arctic.constraints.std_function;
-
- /**
- * A container class for one object that provides a grow handle. This
- * establishes constraints on its child so that it follows the size of this
- * object as it grows.
- *
- * @author Scott Hudson
- */
- public class simple_grow_container extends uni_container
- implements pressable, grow_draggable {
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Full constructor. The boolean parameter controls whether the
- * container does bounding box feedback, or simply grows with no
- * other specific feedback.
- *
- * @param int x the initial x position of this object.
- * @param int y the initial y position of this object.
- * @param int w the initial width of this object.
- * @param int w the initial height of this object.
- * @param loaded_image hnd_img an image for the grow handle.
- */
- public simple_grow_container(int x, int y, int w, int h, loaded_image hnd_img)
- {
- super(x,y,w,h,null);
- if (hnd_img != null) set_handle(hnd_img);
- }
-
- //had:
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Image for the grow handle */
- protected loaded_image _handle = std.line_handle();
-
- /**
- * Image for the grow handle.
- * @return loaded_image the current image for the grow handle.
- */
- public loaded_image handle() {return _handle;}
-
- /**
- * Set the image used for the grow handle.
- * @param loaded_image himg the new image for the grow handle.
- */
- public void set_handle(loaded_image himg)
- {
- if (himg != null)
- {
- _handle = himg;
- damage_self();
- }
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Override set_child to establish and/or remove constraints.
- * @param int at_indx the index to place the child at.
- * @param interactor chld the child interactor.
- */
- public void set_child(int at_indx, interactor chld)
- {
- interactor a_child;
-
- /* First remove w/h constraints placed on old child */
- a_child = child(at_indx);
- if (a_child != null)
- {
- if ((a_child.intrinsic_constraints() & W) == 0)
- a_child.set_w_constraint(NO_CONSTRAINT);
- if ((a_child.intrinsic_constraints() & H) == 0)
- a_child.set_h_constraint(NO_CONSTRAINT);
- }
-
- /* now have super class do the set */
- super.set_child(at_indx, chld);
-
- /* Establish constraints to force new child to have our size */
- if (chld != null)
- {
- if ((chld.intrinsic_constraints() & W) == 0)
- chld.set_w_constraint(std_function.offset(PARENT.W(), 0));
- if ((chld.intrinsic_constraints() & H) == 0)
- chld.set_h_constraint(std_function.offset(PARENT.H(), 0));
- }
- }
-
- //had:
- //* @exception op_not_supported if we don't support children (won't happen).
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Override remove_child to drop constraints.
- * @param int at_index index of child to remove.
- * @return interactor the removed child.
- */
- public interactor remove_child(int at_indx)
- {
- interactor chld;
-
- /* First remove w/h constraints placed on old child */
- chld = child(at_indx);
- if (chld != null)
- {
- if ((chld.intrinsic_constraints() & W) == 0)
- chld.set_w_constraint(NO_CONSTRAINT);
- if ((chld.intrinsic_constraints() & H) == 0)
- chld.set_h_constraint(NO_CONSTRAINT);
- }
-
- /* then let superclass do the job */
- return super.remove_child(at_indx);
- }
-
- //had:
- //* @exception op_not_supported if we don't support children (won't happen).
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Handle mouse button press input to the object. Here, we start dragging.
- * @param event evt the press event.
- * @param Object user_info information associated with this object at pick
- * time.
- * @return boolean indicating whether the input was consumed.
- */
- public boolean press(event evt, Object user_info)
- {
- manager.grow_drag_focus.set_focus_to(this, evt, new point_info(0,0));
-
- return true;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Companion to press(). Here we ignore this.
- * @param event evt the release event.
- * @param Object user_info information associated with this object at pick
- * time.
- * @return boolean indicating whether the input was consumed (here always
- * false).
- */
- public boolean release(event evt, Object user_info)
- {
- return false;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Handle the start of a drag to the object.
- * @param event evt the event "causing" the drag.
- * @param Object user_info information associated with this object at pick
- * time.
- * @return boolean indicating whether the input was consumed.
- */
- public boolean drag_start(event evt, Object user_info)
- {
- /* nothing to do here */
- return true;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Handle a movement during a drag. Here we just set our size to
- * follow the size indicated by the drag.
- *
- * @param event evt the event "causing" the drag.
- * @param int cur_w new width indicated by drag.
- * @param int cur_h new width indicated by drag.
- * @param int st_w initial width of this object.
- * @param int st_h initial height of this object.
- * @param Object user_info information associated with this object at pick
- * time.
- * @return boolean indicating whether the input was consumed.
- */
- public boolean drag_feedback(
- event evt,
- int cur_w, int cur_h,
- int st_w, int st_h,
- Object user_info)
- {
- /* don't go smaller than 1x1 */
- if (cur_w < 1) cur_w = 1;
- if (cur_h < 1) cur_h = 1;
-
- /* set our size */
- set_size(cur_w, cur_h);
- return true;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Handle input corresponding to the end of a drag.
- *
- * @param event evt the event "causing" the drag.
- * @param int cur_w new width indicated by drag.
- * @param int cur_h new width indicated by drag.
- * @param int st_w initial width of this object.
- * @param int st_h initial height of this object.
- * @param Object user_info information associated with this object at pick
- * time.
- * @return boolean indicating whether the input was consumed.
- */
- public boolean drag_end(
- event evt,
- int cur_w, int cur_h,
- int st_w, int st_h,
- Object user_info)
- {
- /* let drag_feedback to all the work */
- return drag_feedback(evt, cur_w, cur_h, st_w, st_h, user_info);
-
- // later we probably need a callback here
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Determine if this object is "picked" by the the given point. In this
- * case, we are only picked if they hit our grow handle at the lower right.
- *
- * @param int pt_x the x coordinate of the query point.
- * @param int pt_y the y coordinate of the query point.
- * @param pick_collector pick_list the result list we add ourselves to if we
- * are picked.
- */
- public void pick(int pt_x, int pt_y, pick_collector pick_list)
- {
- /* don't pick anything unless we are enabled and its inside our bounds */
- if (enabled() && visible() && picked_by(pt_x, pt_y))
- {
- /* pick if they hit the handle */
- if (pt_x <= w() && pt_x >= w()-handle().width() &&
- pt_y <= h() && pt_y >= h()-handle().height())
- pick_list.report_pick(this);
- }
- }
-
- //had:
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Draw the object's current appearance. This draws the children, along
- * with a border rectangle and drag handle at the lower right.
- *
- * @param drawable d the surface to draw on.
- */
- protected void draw_self_local(drawable d)
- {
- /* let superclass draw any children we have */
- super.draw_self_local(d);
-
- /* draw our border and grow handle over the top */
- d.drawRect(0,0,w()-1,h()-1);
- d.drawImage(handle(), w()-handle().width(), h()-handle().height());
- }
-
- //had:
- //* @exception general PROPAGATED.
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
- }
- /*=========================== COPYRIGHT NOTICE ===========================
-
- This file is part of the subArctic user interface toolkit.
-
- Copyright (c) 1996 Scott Hudson and Ian Smith
- All rights reserved.
-
- The subArctic system is freely available for most uses under the terms
- and conditions described in
- http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html
- and appearing in full in the lib/interactor.java source file.
-
- The current release and additional information about this software can be
- found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
-
- ========================================================================*/
-